package com.hyh.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hyh.admin.domain.resources.ResourcesDanmu;
import com.hyh.admin.mapper.resources.ResourcesDanmuMapper;
import com.hyh.admin.service.IResourcesDanmuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;


/*
 *  资源弹幕-实现类
 */
@Service
public class ResourcesDanmuServiceImpl implements IResourcesDanmuService {

    @Autowired
    private ResourcesDanmuMapper resourcesDanmuMapper;

    @Override
    public int sendDanmu(ResourcesDanmu resourcesDanmu) {
        return resourcesDanmuMapper.insert(resourcesDanmu);
    }

    @Override
    public int deleteDanmu(Long id) {
        return resourcesDanmuMapper.deleteById(id);
    }

    @Override
    public List<ResourcesDanmu> selectDanmu(Long resourceId) {
        LambdaQueryWrapper<ResourcesDanmu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ResourcesDanmu::getResourcesId, resourceId);
        return resourcesDanmuMapper.selectList(queryWrapper);
    }

    @Override
    public List<ResourcesDanmu> selectDanmuByUserId(Long userId) {
        LambdaQueryWrapper<ResourcesDanmu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ResourcesDanmu::getUserId, userId);
        return resourcesDanmuMapper.selectList(queryWrapper);
    }

    @Override
    public List<ResourcesDanmu> selectDanmuByResourceIdAndUserId(Long resourceId, Long userId) {
        LambdaQueryWrapper<ResourcesDanmu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ResourcesDanmu::getResourcesId, resourceId);
        queryWrapper.eq(ResourcesDanmu::getUserId, userId);
        return resourcesDanmuMapper.selectList(queryWrapper);
    }

    @Override
    public int likeDanmu(Long id) {
        ResourcesDanmu resourcesDanmu = resourcesDanmuMapper.selectById(id);
        resourcesDanmu.setLikeCount(resourcesDanmu.getLikeCount() + 1);
        return resourcesDanmuMapper.updateById(resourcesDanmu);
    }
}
